﻿#region License
/* ****************************************
 * Allrights reserved by BlueLotus7 
 * 
 * Last updated: 2009-10-01
 * 
 * BlueLotus7@126.com
 * BlueLotus7@vip.qq.com
 * ****************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using BlueLotus7.Common;
using System.Runtime.Serialization;

namespace BlueLotus7.Contract
{
    [DataContract]
    [KnownType(typeof(BaseAccount))]
    public abstract class BaseExternalAccount : BaseAccount, IShadowCopy
    {
        [DataMember]
        protected Guid ownerKey;

        [DataMember]
        protected string mappingObjectKey;

        [DataMember]
        protected string dataSource;

        [DataMember]
        protected DateTime? lastSyncStamp;

        #region Property

        /// <summary>
        /// The owner key.
        /// </summary>
        public Guid OwnerKey
        {
            get { return ownerKey; }
            set { ownerKey = value; }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="ownerKey">The owner key.</param>
        /// <param name="loginId">The login ID.</param>
        public BaseExternalAccount(Guid ownerKey, string loginId)
            : base(loginId)
        {
            this.ownerKey = ownerKey;
            this.Status = AccountStatus.Normal;
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="ownerKey">The owner key.</param>
        /// <param name="status">The status.</param>
        /// <param name="createdStamp">The created stamp.</param>
        /// <param name="lastUpdatedStamp">The last updated stamp.</param>
        public BaseExternalAccount(Guid key, Guid ownerKey, string loginId, string password, AccountStatus status, DateTime createdStamp, DateTime lastUpdatedStamp)
            : base(key, loginId, password, createdStamp, lastUpdatedStamp)
        {
            this.ownerKey = ownerKey;
            this.Status = status;
        }

        #endregion

        #region IShadowCopy Members

        public string MappingObjectKey
        {
            get { return mappingObjectKey; }
        }

        public string DataSource
        {
            get
            {
                return dataSource;
            }
            set
            {
                dataSource = value;
            }
        }

        public DateTime? LastSyncStamp
        {
            get { return lastSyncStamp; }
        }

        public void UpdateSyncStamp()
        {
            lastSyncStamp = DateTime.Now;
        }

        #endregion
    }
}
